﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TKFA.OracleDAL;
using System.Data;

namespace FixedAssets.Module.ManagementProcess
{
    public partial class FA_BuyAudit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                FA_PURCHASEPLAN mod = new FA_PURCHASEPLAN();
                DataTable dt = mod.GetList("").Tables[0];

                DEPARTMENT mod1 = new DEPARTMENT();
                TKFA.Model.DEPARTMENT dpt = new TKFA.Model.DEPARTMENT();

                FA_CORP mod2 = new FA_CORP();
                TKFA.Model.FA_CORP corp = new TKFA.Model.FA_CORP();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    dpt = mod1.GetModel(dt.Rows[i]["SDEPARTMENTCODE"].ToString(), dt.Rows[i]["SCORPCODE"].ToString());
                    dt.Rows[i]["SDEPARTMENTCODE"] = dpt.SDEPARTMENTNAME;
                    dpt = new TKFA.Model.DEPARTMENT();

                    corp = mod2.GetModel(dt.Rows[i]["SCORPCODE"].ToString());
                    dt.Rows[i]["SCORPCODE"] = corp.SCORPNAME;
                    corp = new TKFA.Model.FA_CORP();
                }

                this.C1GridView1.DataSource = dt;
                this.C1GridView1.DataBind();
            }

        }

        protected void btnReject_Click(object sender, EventArgs e)
        {
            string strID = Label3.Text.ToString();
            FA_PURCHASEPLAN mod = new FA_PURCHASEPLAN();
            string strSql = "update FA_PURCHASEPLAN set SPLANSTATUS = 2,SNOTE='"+this.TextBox1.Text.ToString()+"'  where planid = " + strID;
            mod.DoAudit(strSql);
        }

        protected void btnAccept_Click(object sender, EventArgs e)
        {
            string strID = Label3.Text.ToString();
            FA_PURCHASEPLAN mod = new FA_PURCHASEPLAN();
            string strSql = "update FA_PURCHASEPLAN set SPLANSTATUS = 3 where planid = " + strID;
            mod.DoAudit(strSql);
        }

        

        protected void C1GridView1_RowCommand(object sender, C1.Web.Wijmo.Controls.C1GridView.C1GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Detail")
            {
                Button button = (Button)e.CommandSource;
                GridViewRow row = (GridViewRow)button.Parent.Parent;
                string a = row.Cells[2].Text.ToString();

                this.Label3.Text = a;

                FA_PURCHASEDATA mod = new FA_PURCHASEDATA();
                DataTable dt = new DataTable();
                TKFA.Model.FA_PURCHASEDATA plandata = new TKFA.Model.FA_PURCHASEDATA();

                string strsql = "planID = " + a;
                dt = mod.GetList(strsql).Tables[0];

                FA_CORP mod2 = new FA_CORP();
                TKFA.Model.FA_CORP corp = new TKFA.Model.FA_CORP();

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    

                    corp = mod2.GetModel(dt.Rows[i]["SCORPCODE"].ToString());
                    dt.Rows[i]["SCORPCODE"] = corp.SCORPNAME;
                    corp = new TKFA.Model.FA_CORP();
                }

                this.C1GridView2.DataSource = dt;
                this.C1GridView2.DataBind();

            }
        }
    }
}